
import { NativeModules, Platform } from 'react-native';

const { MIMCModule } = NativeModules;
const isIOS = Platform.OS == 'ios';




let MIMC = {

  /**
   * 初始化登陆的token
   * @param token
   */
  initToken(token){
    MIMCModule.initToken(token);
  },

  /**
   * 用户登陆
   * @param appId
   * @param appAccount
   * @param resolverUrl
   * @param ucUrl
   */
  login(appId, appAccount, resolverUrl='', ucUrl = ''){
    if(isIOS){
      MIMCModule.login(appId,appAccount);
    } else {
      MIMCModule.login(appId,appAccount,resolverUrl,ucUrl);
    }
  },

  /**
   * 用户登出
   */
  logout(){
    MIMCModule.logout();
  },

  /**
   * 发送单聊消息
   * @param toAccount
   * @param payload
   * @param bizType
   */
  sendMessage(toAccount,payload,bizType){
    let params = {
      toAccount: toAccount,
      payload: payload,
      bizType: bizType
    };
    MIMCModule.sendMessage(params);
  },

  /**
   * 发送在线消息
   * @param toAccount
   * @param payload
   * @param bizType
   */
  sendOnlineMessage(toAccount,payload,bizType){
    let params = {
      toAccount: toAccount,
      payload: payload,
      bizType: bizType
    };
    MIMCModule.sendOnlineMessage(params);
  },

  /**
   * 发送群聊消息
   * @param topicId
   * @param payload
   * @param bizType
   */
  sendGroupMessage(topicId,payload,bizType){
    let params = {
      topicId: topicId,
      payload: payload,
      bizType: bizType
    };
    MIMCModule.sendGroupMessage(params);
  },

  /**
   * 发送无限群聊消息
   * @param topicId
   * @param payload
   * @param bizType
   */
  sendUnlimitedGroupMessage(topicId,payload,bizType){
    let params = {
      topicId: topicId,
      payload: payload,
      bizType: bizType
    };
    MIMCModule.sendUnlimitedGroupMessage(params);
  },


};

export default MIMC;
